<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{asset('/css/web/user/info.css')}}">
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.member_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">基本信息</div>
                @if (count($errors) > 0)

                        <div class="alert alert-danger">
                            @foreach ($errors->all() as $error)
                                <input type="hidden" id="error_msg" value="{{ $error }}">
                            @endforeach
                        </div>
                    @endif
                <div class="head f-cb">
                    <div class="avatar">
                        <img src="{{array_get($data,'pic')}}" width="88" height="88" class="uploaded-image" />
                        <div class="avatar_edit">编辑头像</div>
                    </div>
                    <input type="file" class="fileupload" name="image" style="display:none" id="js-photo-upload" />
                    <input type="hidden" name="img_path" value="{{array_get($data,'pic')}}" />
                    <div class="prompt">支持JPG、PNG、GIF等格式的图片，且小于2M!</div>
                </div>

                <div class="table">
                    <table>
                        <tr>
                            <td class="type_title">用户名&nbsp;：&nbsp;</td>
                            <td class="type_con">{{array_get($data,'name')}}</td>
                        </tr>
                        <tr>
                            <td class="type_title">性别&nbsp;：&nbsp;</td>
                            <td class="type_con">
                                <label class="men"><input type="radio" name="sex" @if(array_get($data,'sex') == '1') {{"checked"}} @endif value='1'>男</label>
                                <label class="women"><input type="radio" name="sex" @if(array_get($data,'sex') == '2') {{"checked"}} @endif value='2' >女</label>
                            </td>
                        </tr>
                        <tr>
                            <td class="type_title">邮箱&nbsp;：&nbsp;</td>
                            <td class="type_con">
                                @if(!empty(array_get($data,'email')))
                                    您验证的邮箱：{{array_get($data,'email')}}  若已丢失或停用，请<a href="{{asset('/member/user/email_revise')}}" class="ph">&nbsp;立即更换</a>。
                                @else
                                    您还没验证邮箱，<a href="{{asset('/member/user/email_revise')}}" class="email">绑定邮箱&nbsp;</a>可用于快速找回密码。
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <td class="type_title">手机&nbsp;：&nbsp;</td>
                            <td class="type_con">
                                您验证的手机：{{substr_replace(array_get($data,'phone'), '****', 3, 4)}}  若已丢失或停用，请<a href="{{asset('/member/user/phone_revise')}}" class="ph">&nbsp;立即更换</a>。

                            </td>
                        </tr>
                        <tr>
                            <td class="type_title">企业认证&nbsp;：&nbsp;</td>
                            <td class="type_con">
                                @if(!empty(array_get($data,'identification_type')) && array_get($data,'identification_type') == 2)
                                    已认证
                                @else
                                    未认证   认证企业拥有更多优惠，<a href="{{asset('/member/user/company')}}" class="rz">立即认证</a>。
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <td class="type_title">账户安全等级&nbsp;：&nbsp;</td>
                            <td class="type_con">
                                <div class="level fl">
                                    <?php
                                        $level = 0;
                                        if(array_get($data,'email')) $level += 0.5;
                                        if(array_get($data,'pay_pwd')) $level += 0.5;
                                    ?>
                                    <input type="hidden" id="level" name="" value="{{$level}}">
                                    <span></span>
                                </div>
                                <span class="level_word">较低</span>
                                <a href="{{asset('/member/user/safe')}}" class="jm_btn4 btn flr">去提升</a>
                            </td>
                        </tr>
                        <tr>
                            <td class="type_title">默认收货地址&nbsp;：&nbsp;</td>
                            <td class="type_con">
                                <div class="p fl" style="margin-top:4px;">
                                    @if(!empty(array_get($data,'address')))
                                        @foreach(array_get($data,'address') as $value)
                                            @if($value['is_default'] == 1)
                                                {{$value['regions']['merger_name'] . $value['address']}}
                                            @endif
                                        @endforeach
                                    @endif
                                </div>
                                <a href="{{asset('/member/address')}}" class="jm_btn4 btn flr">修改</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="save-box">
                    <input type='button' value='保存' class="jm_btn5 js-save-member" />
                    <input type="hidden" id="upload-img" />
                </div>

            </div>
        </div>
    </div>
</div>
@include('web.layout.footer')
</body>
<script>
    $(function (e) {
        var member_img = null ;
        // 图片上传
        $('#js-photo-upload').change(function(){
            var url = AJAX_URL + '/uploads/images';
            var files =  this.files[0];
            var formFile = new FormData();
            formFile.append("image", files);
            $.ajax({
                url: url,
                type: "POST",
                data: formFile,
                contentType: false,
                cache: false,
                processData: false,
                // 显示加载图片
                success: function (res) {
                    if (res.status == 0){
                        $(".uploaded-image").attr('src',res.path);
                        $('input[name="img_path"]').val(res.path);
                        layer.alert('图片上传成功', {
                            title:'提示',
                            icon: 1
                        });
                    } else {
                        layer.alert('图片上传失败', {
                            title:'提示',
                            icon: 2
                        });
                    }
                },
                error: function () { }
            });
        })
        $(".avatar_edit").click(function () {
            $("#js-photo-upload").trigger("click");

        });



        $(".avatar").hover(function () {
            $('.avatar_edit').show();
        }, function(){
            $('.avatar_edit').hide();
        });


        $('.js-save-member').click(function () {
            var sex = $('input[name="sex"]:checked').val();
            var pic_path = $('input[name="img_path"]').val();
            var token = $('input[name="_token"]').val();
            var url = AJAX_URL + '/member/user/updateinfo';

            $.get(url, {path: pic_path, sex: sex, _token: token}, function (res) {
                if (res.code == 0) {
                    layer.alert('信息更新成功', {
                        icon: 1
                    });
                } else {
                    layer.alert(res.message, {
                        icon: 2
                    });
                }
            }, 'json')
        })

        var level = $('#level').val();
        $('.level span').css("width",level*100+'%');
        if(level == 0){
            $('.level_word').html('较低');
        }else if(level ==0.5 ){
            $('.level_word').html('中等');
        }else if(level == 1 ){
            $('.level_word').html('完善');
        }
        var error_msg=$('#error_msg').val();
        if(error_msg){
            layer.alert(error_msg, {
                icon: 1
            },function () {
                window.location.href='/member/user/company';
            });
        }


    })
</script>
</html>